import { _decorator, Component, director, EventTouch, Node, Sprite } from 'cc';
import { WeaponShowManager } from './WeaponShowManager';
import { PlayRoleManager } from './PlayRoleManager';
const { ccclass, property } = _decorator;

@ccclass('GameManager')
export class GameManager extends Component {

    @property(Node)
    private weaponPageNoe:Node;

    @property(Node)
    private weaponIconNoe:Node;

    @property(Node)
    private playRolePageNoe:Node;

    @property(Node)
    private fightIconNode:Node;

    @property(Node)
    private haoSanNoe:Node;

    @property(Node)
    private zhuZiNode:Node;

    @property(Node)
    private yinSiNode:Node;

    @property(Node)
    private yinWuNode:Node;

    private weaponShowManager:WeaponShowManager;

    private playRoleManager:PlayRoleManager;

    start() {

        //this.node.getChildByName("bg").getComponent(Sprite).spriteFrame = LoadingManager.bigFrames.get("game_root_bg");
        
        this.weaponShowManager = this.weaponPageNoe.getComponent(WeaponShowManager);

        this.playRoleManager = this.playRolePageNoe.getComponent(PlayRoleManager);

        this.weaponIconNoe.on(Node.EventType.TOUCH_END, () => {
            this.weaponShowManager.showPage();
        });

        this.haoSanNoe.on(Node.EventType.TOUCH_END, (touchObj:EventTouch) => {
            this.onRoleClick(touchObj);
        });
        this.zhuZiNode.on(Node.EventType.TOUCH_END, (touchObj:EventTouch) => {
            this.onRoleClick(touchObj);
        });
        this.yinSiNode.on(Node.EventType.TOUCH_END, (touchObj:EventTouch) => {
            this.onRoleClick(touchObj);
        });
        this.yinWuNode.on(Node.EventType.TOUCH_END, (touchObj:EventTouch) => {
            this.onRoleClick(touchObj);
        });

        this.fightIconNode.on(Node.EventType.TOUCH_END, (touchObj:EventTouch) => {
            director.loadScene("fight");
        });
    }

    private isRealTouch(eventTouch:EventTouch) {
        return eventTouch.target == eventTouch.currentTarget && eventTouch.currentTarget.name == 'GameRoot';
    }

    private onRoleClick(touchObj:EventTouch) {
        console.log("onRoleClick:" + touchObj.target.name);
        this.playRoleManager.showRole(touchObj.target.name);
    }

    update(deltaTime: number) {
        
    }
}

